<?php

namespace Drupal\shusy_store\ViewsController;

use Drupal\shusy_store\ViewsController\handler\field\ShusyStoreEditLinkViewsField;
use Drupal\shusy_store\ViewsController\handler\field\ShusyStoreSexViewsField;
use Drupal\shusy_store\ViewsController\handler\field\ShusyStoreStatusViewsField;
use Drupal\shusy_store\ViewsController\handler\field\ShusyStoreTypeViewsField;
use Drupal\shusy_store\ViewsController\handler\filter\ShusyStoreInStoreViewsFilter;
use Drupal\shusy_store\ViewsController\handler\filter\ShusyStoreSexViewsFilter;
use Drupal\shusy_store\ViewsController\handler\filter\ShusyStoreStatusViewsFilter;
use Drupal\shusy_store\ViewsController\handler\filter\ShusyStoreTypeViewsFilter;
use EntityDefaultViewsController;


class ShusyStoreViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $revision_table = $this->info['revision table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => ShusyStoreEditLinkViewsField::class,
        ],
      ];
      $info[$table]['sex'] = [
        'title' => '性别 0 未知 1 男 2 女',
        'help' => '性别 0 未知 1 男 2 女',
        'real field' => 'sex',
        'field' => [
          'handler' => ShusyStoreSexViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreSexViewsFilter::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 审核中 1 已通过 2 未通过',
        'help' => '状态 0 审核中 1 已通过 2 未通过',
        'real field' => 'status',
        'field' => [
          'handler' => ShusyStoreStatusViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreStatusViewsFilter::class,
        ],
      ];

      $info[$table]['in_store'] = [
        'real field' => 'id',
        'title' => t('店铺过滤'),
        'help' => t('是否是当前登录的用户关联的店铺'),
        'group' => 'shusy_store',
        'filter' => [
          'handler' => ShusyStoreInStoreViewsFilter::class,
        ],
      ];
      $info[$table]['type'] = [
        'title' => '类型 0 加盟入驻 1 平台直营',
        'help' => '类型 0 加盟入驻 1 平台直营',
        'real field' => 'type',
        'field' => [
          'handler' => ShusyStoreTypeViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreTypeViewsFilter::class,
        ],
      ];
      $info[$revision_table]['type'] = [
        'title' => '类型 0 加盟入驻 1 平台直营',
        'help' => '类型 0 加盟入驻 1 平台直营',
        'real field' => 'type',
        'field' => [
          'handler' => ShusyStoreTypeViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreTypeViewsFilter::class,
        ],
      ];

      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
